package com.sc.auction.goods.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sc.auction.common.util.R;
import com.sc.auction.goods.pojo.Images;
import com.sc.auction.goods.service.ImagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sc.auction.common.util.R;
import com.sc.auction.goods.pojo.Images;
import com.sc.auction.goods.service.ImagesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Lsc
 * @since 2020-09-01
 */
@CrossOrigin
@RestController
@RequestMapping("/goods/images")
public class ImagesController {
    @Autowired
    private ImagesService imagesService;
    @GetMapping(value = "/getImage")
    public R getImageByGoodsCode1(@RequestParam("goodsCode") String goodsCode){
        QueryWrapper queryWrapper = new QueryWrapper();
        if(goodsCode!=null&&!goodsCode.isEmpty()){
            queryWrapper.eq("goodsCode",goodsCode);
        }
        Images images=imagesService.getOne(queryWrapper);
        if(images!=null){
            return R.ok().data("image",images);
        }else {
            return R.error();
        }
    }
    @Autowired
    private ImagesService imagesServicel;
    @ApiOperation("通过code得到图片")
    @GetMapping(value = "/getImageByGoodsCode")
    public R getImageByGoodsCode(@RequestParam("code") String code){
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("goodsCODE",code);
        Images images=imagesServicel.getOne(queryWrapper);

        return R.ok().data("imageURL",images.getUrl());
    }
}

